package com.niit.serviceorder.controller;

import com.niit.common.entity.TbOrder;
import com.niit.serviceorder.service.TbOrderService;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.beans.factory.annotation.Value;
import org.springframework.web.bind.annotation.*;

import java.util.List;

@RestController
@RequestMapping("/orders")
public class TbOrderController {

    @Autowired
    private TbOrderService tbOrderService;

    @Value(value = "${server.port}")
    String port;
    @GetMapping
    public List<TbOrder> getAllOrders() {
        System.out.println("port:"+port);
        return tbOrderService.getAllOrders();
    }

    @GetMapping("/{id}")
    public TbOrder  getOrderById(@PathVariable Long id) {
        return tbOrderService.getOrderById(id);
    }

    @PostMapping
    public int createOrder(@RequestBody TbOrder order) {
        return tbOrderService.createOrder(order);
    }

    @PutMapping("/{id}")
    public int updateOrder(@PathVariable Long id, @RequestBody TbOrder order) {
        return tbOrderService.updateOrder(order);
    }

    @DeleteMapping("/{id}")
    public int deleteOrder(@PathVariable Long id) {

        return tbOrderService.deleteOrder(id);
    }
}